#install.packages('ggmap')
#install.packages("dplyr")
#install.packages("plyr")
#install.packages("leaflet")
library(ggmap)
## Loading required package: ggplot2
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(plyr)
## -------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## -------------------------------------------------------------------------
##
## Attaching package: 'plyr'
## The following objects are masked from 'package:dplyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.4.4
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#sapply(var1, tolower), converting to lower
tourist_places_list<-c("bryant park","one world observatory","","The Tour","park slope", "Columbus Circle","Rockefeller Center","United Nations Headquarters","Ellis Island","barclays center","NYC Information Center","The museum of modern art","Elegant Tightwad Shopping Tours","Statue of Liberty","Museum of the Moving Image","New York Botanical Garden","New York Botanical Garden","Lincoln Center", "Bronx Opera House Hotel", "theater for a new audience","Tiffany & Co. Foundation Gallery",
'Chinese Scholars Garden',
'Museum of Sex',
'City Reliquary',
'Staten Island Ferry',
'MCC Theater',
'Century 21',
'Socrates Sculpture Park',
'Wave Hill House',
'Brooklyn History and Pizza Tour',
'LIC Flea',
'Yankee Stadium',
"Brandy's Piano Bar",
'Tenement Museum',
'african burial grounds',
'City Winery',
'the lakeside restaurant',
'Arthur Avenue',
'Flushing Meadows-Corona Park',
'City Island',
'Trinity Church',
'Citi Field',
'Brooklyn Brewery',
'coney island',
'FAO Schwarz',
'230 Fifth',
'The Queens Museum',
'La Marina',
'Brooklyn Bridge',
'Tango House',
'brooklyn historical society',
'Gotham West Market',
'The Metropolitan Museum of Art',
'Brooklyn Museum',
'Empire State Building',
'The Guggenheim Museum',
'Refinery Hotel',
'New York Public Library',
'Jacob K. Javits Center',
'The New Museum',
'Museum of Mathematics',
'Four Freedoms Park ',
'museum of natural history',
'The Staten Island Zoo',
'Green-wood Cemetery'
)
#tourist_places1<-sapply(tourist_places, tolower)
tourist_places_list_df<-as.data.frame(tourist_places_list)
geo_tourist_places_list<-geocode(as.character(tourist_places_list_df$tourist_places_list))
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=bryant%20park&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=one%20world%20observatory&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=The%20Tour&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=park%20slope&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Columbus%20Circle&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Rockefeller%20Center&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=United%20Nations%20Headquarters&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Ellis%20Island&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=barclays%20center&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=NYC%20Information%20Center&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=The%20museum%20of%20modern%20art&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Elegant%20Tightwad%20Shopping%20Tours&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Statue%20of%20Liberty&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Museum%20of%20the%20Moving%20Image&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=New%20York%20Botanical%20Garden&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=New%20York%20Botanical%20Garden&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "New York
## Botanical Garden"
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Lincoln%20Center&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Bronx%20Opera%20House%20Hotel&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=theater%20for%20a%20new%20audience&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Tiffany%20&%20Co.%20Foundation%20Gallery&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Chinese%20Scholars%20Garden&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Museum%20of%20Sex&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=City%20Reliquary&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Staten%20Island%20Ferry&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Staten
## Island Ferry"
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=MCC%20Theater&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Century%2021&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Socrates%20Sculpture%20Park&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Wave%20Hill%20House&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Brooklyn%20History%20and%20Pizza%20Tour&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=LIC%20Flea&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Yankee%20Stadium&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Brandy's%20Piano%20Bar&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Tenement%20Museum&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=african%20burial%20grounds&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=City%20Winery&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=the%20lakeside%20restaurant&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Arthur%20Avenue&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Flushing%20Meadows-Corona%20Park&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Flushing
## Meadows-Corona Park"
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=City%20Island&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Trinity%20Church&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Citi%20Field&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Brooklyn%20Brewery&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=coney%20island&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=FAO%20Schwarz&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=230%20Fifth&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=The%20Queens%20Museum&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=La%20Marina&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Brooklyn%20Bridge&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Tango%20House&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=brooklyn%20historical%20society&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Gotham%20West%20Market&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Gotham
## West Market"
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=The%20Metropolitan%20Museum%20of%20Art&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Brooklyn%20Museum&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Empire%20State%20Building&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=The%20Guggenheim%20Museum&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Refinery%20Hotel&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Refinery
## Hotel"
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=New%20York%20Public%20Library&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Jacob%20K.%20Javits%20Center&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Jacob K.
## Javits Center"
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=The%20New%20Museum&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Museum%20of%20Mathematics&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Museum of
## Mathematics"
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Four%20Freedoms%20Park%20&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=museum%20of%20natural%20history&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=The%20Staten%20Island%20Zoo&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Green-wood%20Cemetery&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Green-
## wood Cemetery"
tourist_places_list_main<-cbind(tourist_places_list_df,geo_tourist_places_list)
geocode("Columbus Circle")
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Columbus%20Circle&sensor=false
## lon lat
## 1 -73.98237 40.76803
filter(tourist_places_list_main, tourist_places_list_main$tourist_places_list == "Columbus Circle")
## Warning: package 'bindrcpp' was built under R version 3.4.4
## tourist_places_list lon lat
## 1 Columbus Circle -73.98237 40.76803
tourist_places_list_main$lat[which(tourist_places_list_main$tourist_places_list == "Columbus Circle" )]<-"40.76803"
tourist_places_list_main$lon[which(tourist_places_list_main$tourist_places_list == "Columbus Circle" )]<-"-73.9832"
tourist_places_list_main$lat[which(tourist_places_list_main$tourist_places_list == "one world observatory" )]<-"40.7127"
tourist_places_list_main$lon[which(tourist_places_list_main$tourist_places_list == "one world observatory" )]<-"-74.0134"
tourist_places_list_main$lat[which(tourist_places_list_main$tourist_places_list == "Ellis Island" )]<-"40.6995"
tourist_places_list_main$lon[which(tourist_places_list_main$tourist_places_list == "Ellis Island" )]<-"-74.0396"
tourist_places_list_main$lat[which(tourist_places_list_main$tourist_places_list == "coney island")]<-"40.5755"
tourist_places_list_main$lon[which(tourist_places_list_main$tourist_places_list == "coney island" )]<-"-74.0396"
tourist_places_list_main$lat[which(tourist_places_list_main$tourist_places_list == "Brooklyn Museum")]<-"40.6712"
tourist_places_list_main$lon[which(tourist_places_list_main$tourist_places_list == "Brooklyn Museum" )]<-"-73.9636"
tourist_places_list_main$lat[which(tourist_places_list_main$tourist_places_list == "The Metropolitan Museum of Art")]<-"40.7794"
tourist_places_list_main$lon[which(tourist_places_list_main$tourist_places_list == "The Metropolitan Museum of Art" )]<-"-73.9632"
tourist_places_list_main$lat[which(tourist_places_list_main$tourist_places_list == "Four Freedoms Park")]<-"40.7508"
tourist_places_list_main$lon[which(tourist_places_list_main$tourist_places_list == "Four Freedoms Park" )]<-"-73.9604"
tourist_places_list_main<-filter(tourist_places_list_main, lat != "NA")
tourist_places_list_main$lat<-as.numeric(tourist_places_list_main$lat)
tourist_places_list_main$lon<-as.numeric(tourist_places_list_main$lon)
#importing march data file
Listing_March_18<-read.csv("/Users/ranjitarajeevashetty/Downloads/March_2018/listings.csv", header = TRUE)
stations_list <- read.csv('/Users/ranjitarajeevashetty/Documents/R-Visualization/R Project/subway.csv', header=TRUE)
#substr('ABC_EFG_HIG_ADF_AKF_MNB', 9, 11)
stations_list$longitude<- as.numeric(substr(stations_list$the_geom, 8, 20))
#stations_list$laltitude<-as.numeric(substr(stations_list$the_geom, 27, 44))
#gsub(" .*$", "",stations_list$the_geom)
d1<-substring(stations_list$the_geom, regexpr(" ", stations_list$the_geom) + 1)
d2<-substring(d1, regexpr(" ", d1) + 1)
d3<-gsub(')','',d2)
latitude<-as.numeric(d3)
stations_list_lat_long<- cbind(stations_list, latitude)
Listing_March_18%>%distinct(neighbourhood_group)
## neighbourhood_group
## 1 Manhattan
## 2 Brooklyn
## 3 Queens
## 4 Bronx
## 5 Staten Island
content<- paste("neighbourhood:", Listing_March_18$neighbourhood,"<br/>",
"neighbourhood_group:", Listing_March_18$neighbourhood_group,"<br/>",
"room_type:",Listing_March_18$room_type,"<br/>",
"Availability:", Listing_March_18$availability_365,"<br/>")
library(RColorBrewer)
pal = colorFactor("Set1", domain = Listing_March_18$neighbourhood_group) # Grab a palette
color_offsel1 = pal(Listing_March_18$neighbourhood_group)
#geocode("Elegant Tightwad Shopping Tours")
#adding subway image
NYU_Subway <- makeIcon(
iconUrl = "https://images-na.ssl-images-amazon.com/images/I/41NPZ9vZKNL.png",
iconWidth = 25, iconHeight = 25)
mclust<-leaflet(Listing_March_18)%>%addTiles()%>%addCircleMarkers(color = color_offsel1,popup = content,clusterOptions = markerClusterOptions(), group ="Airbnb Listing" )%>%
addLegend(pal=pal,values=~Listing_March_18$neighbourhood_group, title = "Neighbourhood")%>%setView(-73.9949344, 40.7179112, zoom = 11)%>%addMarkers(data= tourist_places_list_main, group = "Tourist Places",popup = paste("Tourist_place_name:",tourist_places_list_main$tourist_places_list, "<br>"))%>%addMarkers(data= stations_list_lat_long, group = "Subway Station",icon=NYU_Subway)%>%
addProviderTiles(providers$Stamen.Toner, group = "Toner") %>%
addProviderTiles(providers$Stamen.TonerLite, group="Toner Lite") %>%
# Layers control
addLayersControl(
baseGroups = c("OpenStreetMap", "Toner", "Toner Lite"),
overlayGroups = c("Airbnb Listing","Tourist Places","Subway Station"),
options = layersControlOptions(collapsed = TRUE) )%>%setView(-73.9949344, 40.7179112, zoom = 13)
## Assuming "longitude" and "latitude" are longitude and latitude, respectively
## Assuming "lon" and "lat" are longitude and latitude, respectively
## Assuming "longitude" and "latitude" are longitude and latitude, respectively
mclust
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.